package com.example.t410.service.serviceImpl;

import com.example.t410.DTO.IntroductionPCCDTO;
import com.example.t410.VO.GetPCCDatailVO;
import com.example.t410.VO.GetPCCVO;
import com.example.t410.entity.Doctor;
import com.example.t410.entity.PsychologicalCounselingCenter;
import com.example.t410.entity.TimeSlot;
import com.example.t410.mapper.IntroductionMapper;
import com.example.t410.service.IntroductionService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;

@Service
public class IntroductionServiceImpl implements IntroductionService {
    @Autowired
    IntroductionMapper introductionMapper;
    @Override
    public List<GetPCCVO> findPCCs(IntroductionPCCDTO introductionPCCDTO) {
        List<PsychologicalCounselingCenter> PCCList = introductionMapper.findPCCs(introductionPCCDTO);
        List<GetPCCVO> pccvos = new ArrayList<>();
        for (PsychologicalCounselingCenter pcc : PCCList)
        {
            GetPCCVO getPCCVO = new GetPCCVO();
            BeanUtils.copyProperties(pcc,getPCCVO);
            pccvos.add(getPCCVO);
        }
        return pccvos;
    }

    @Override
    public GetPCCDatailVO findDatial(Long id) {

        PsychologicalCounselingCenter newPcc = introductionMapper.findPCCById(id);
        List<Doctor> doctors =  introductionMapper.findDoctors(id);
        List<TimeSlot> timeSlots = introductionMapper.findTime(id);
        GetPCCDatailVO getPCCDatailVO = new GetPCCDatailVO();
        BeanUtils.copyProperties(newPcc,getPCCDatailVO);
        getPCCDatailVO.setDoctorList(doctors);
        getPCCDatailVO.setTimeSlots(timeSlots);
        return getPCCDatailVO;
    }
}
